import request from '#/utils/requestAbort';

export async function fetchSequences(marketId, date, type) {
  // 获取序列列表信息
  return request(
    `/tianji-transaction/centralizedBidding/fetchSequences/${marketId}/${
      date + (type ? `/${type}` : '')
    }`,
  );
}
// 省份-交易中心-场站（数据权限）
export async function queryMarketList(menuCode) {
  return request(`/power/dataPower/common/${menuCode}/t_station`, {
    method: 'GET',
  });
}

export async function fetchSequencesFuture() {
  // 获取未开始申报的序列信息
  return request(`/tianji-transaction/centralizedBidding/fetchSequences`);
}

export async function fetchPrograms(sequenceId, queryDel) {
  // 获取序列下的方案信息
  return request(`/tianji-transaction/centralizedBidding/fetchPrograms/${sequenceId}/${queryDel}`);
}

export async function fetchHourOrderInfo(menuCode, programId) {
  // 获取方案下的时段信息
  return request(
    `/tianji-transaction/centralizedBidding/fetchHourOrderInfo/${menuCode}/${programId}`,
  );
}

export async function fetchUnit(sequenceId, menuCode, params) {
  // 获取序列下交易单元限额信息
  return request(`/tianji-transaction/centralizedBidding/fetchUnit/map/${sequenceId}/${menuCode}`, {
    method: 'POST',
    data: params,
  });
}

export async function tenDaysTradeSubmit(menuCode, data) {
  // 保存、定时申报、立即申报方案
  return request(`/tianji-transaction/centralizedBiddingTask/submit/${menuCode}`, {
    method: 'POST',
    data: data,
  });
}

export async function fetchUnitSubmitInfos(sequenceId, menuCode) {
  // 获取每个交易单元在方案中的申报信息情况（方案总览）
  return request(
    `/tianji-transaction/centralizedBidding/fetchUnitSubmitInfos/${sequenceId}/${menuCode}`,
  );
}

export async function fetchOperateLogs(programId) {
  // 获取操作日志列表
  return request(`/tianji-transaction/centralizedBidding/fetchOperateLogs/${programId}`);
}

export async function fetchUnitLimitPowerPageViewData(sequenceId, menuCode) {
  // 分单元限额查询页面数据获取
  return request(
    `/tianji-transaction/centralizedBidding/fetchUnitLimitPowerPageViewData/${sequenceId}/${menuCode}`,
  );
}

export async function fetchStatusPageViewData(sequenceId, menuCode) {
  // 获取状态查询页面数据
  return request(
    `/tianji-transaction/centralizedBidding/fetchStatusPageViewData/${sequenceId}/${menuCode}`,
  );
}

export async function asyncUpdateTradeCenterSubmitStatus(sequenceId) {
  // 异步请求更新交易单元在交易中心的申报情况
  return request(
    `/tianji-transaction/centralizedBidding/asyncUpdateTradeCenterSubmitStatus/${sequenceId}`,
  );
}

export async function cancelTimelySubmit(programId) {
  // 取消方案定时申报
  return request(`/tianji-transaction/centralizedBidding/cancelTimelySubmit/${programId}`, {
    method: 'POST',
  });
}

export async function deleteProgram(menuCode, programId) {
  // 删除方案
  return request(`/tianji-transaction/centralizedBidding/deleteProgram/${menuCode}/${programId}`, {
    method: 'POST',
  });
}

export async function exportProgram(programId) {
  // 导出方案申报信息
  let type = 'excel'; // 导出类型,目前只支持传excel
  return request(`/tianji-transaction/centralizedBidding/exportProgram/${programId}/${type}`, {
    method: 'POST',
    responseType: 'blob',
    getResponse: true,
  });
}

export async function fetchTradeTime() {
  // 获取当前交易中心的当前时间
  return request(`/tianji-transaction/tradeTime/fetchTradeTime`);
}

export async function fetchUsedUnit(sequenceId) {
  // 获取指定序列下已有方案的交易单元列表
  return request(`/tianji-transaction/centralizedBidding/fetchUnit/programList/${sequenceId}`);
}

export async function fetchStatusPageViewData_SD(date) {
  // 获取状态查询页面数据__山东
  return request(`/tianji-transaction/centralizedBiddingStatus/shandong/${date}`, {
    method: 'GET',
  });
}

export async function undoCommit(id) {
  // 状态查询撤销
  return request(`/tianji-transaction/centralizedBiddingStatus/shandong/undoCommit/${id}`, {
    method: 'GET',
  });
}

// 导入模板下载
export async function getTemplate(marketId, sequenceId) {
  return request(`/tianji-transaction/centralizedBiddingTask/template/${marketId}/${sequenceId}`, {
    method: 'GET',
    responseType: 'blob',
  });
}
